<template>
  <Dialog v-model="dialogVisible" title="参评人员详情" width="800px" v-loading="loading">
    <el-descriptions :column="2" border>
      <el-descriptions-item label="姓名">
        {{ candidateData.name || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="身份证号">
        {{ candidateData.idNumber || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="性别">
        {{ candidateData.gender === 1 ? '男' : candidateData.gender === 2 ? '女' : '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="出生日期">
        {{ candidateData.birthDate || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="联系电话">
        {{ candidateData.mobile || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="电子邮箱">
        {{ candidateData.email || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="学历">
        {{ getEducationName(candidateData.education) }}
      </el-descriptions-item>
      <el-descriptions-item label="工作单位">
        {{ candidateData.workUnit || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="部门">
        {{ candidateData.department || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="职位">
        {{ candidateData.position || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="申报职业">
        {{ candidateData.appliedProfession || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="申报等级">
        <el-tag>{{ candidateData.appliedLevel || '-' }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="工作年限">
        {{ candidateData.workYears || 0 }}年
      </el-descriptions-item>
      <el-descriptions-item label="报名状态">
        <el-tag :type="getRegistrationStatusColor(candidateData.registrationStatus)">
          {{ getRegistrationStatusName(candidateData.registrationStatus) }}
        </el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="报名时间">
        {{ candidateData.registrationTime || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="确认时间">
        {{ candidateData.confirmationTime || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="数据来源">
        {{ getDataSourceName(candidateData.dataSource) }}
      </el-descriptions-item>
      <el-descriptions-item label="导入批次ID">
        {{ candidateData.importBatchId || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="备注信息" :span="2">
        {{ candidateData.remarks || '-' }}
      </el-descriptions-item>
    </el-descriptions>

    
    <template #footer>
      <el-button @click="dialogVisible = false">关闭</el-button>
    </template>
  </Dialog>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import * as EvalCandidateApi from '@/api/eval/candidate/index'

const dialogVisible = ref(false)
const candidateData = ref({} as any)
const loading = ref(false)

const getEducationName = (education: number) => {
  const educationMap = { 1: '小学', 2: '初中', 3: '高中', 4: '中专', 5: '大专', 6: '本科', 7: '硕士', 8: '博士' }
  return educationMap[education] || '-'
}

const getLevelName = (level: number) => {
  const levelMap = { 1: '初级', 2: '中级', 3: '高级', 4: '技师', 5: '高级技师' }
  return levelMap[level] || '-'
}

const getRegistrationStatusName = (status: number) => {
  const statusMap = { 1: '已报名', 2: '已确认', 3: '已取消' }
  return statusMap[status] || '-'
}

const getRegistrationStatusColor = (status: number) => {
  const colorMap = { 1: 'warning', 2: 'success', 3: 'danger' }
  return colorMap[status] || 'info'
}

const getDataSourceName = (source: number) => {
  const sourceMap = { 1: '手动录入', 2: '批量导入', 3: '系统同步' }
  return sourceMap[source] || '-'
}

const open = async (id: number) => {
  dialogVisible.value = true
  loading.value = true

  try {
    const data = await EvalCandidateApi.getCandidateInfo(id)
    candidateData.value = data
  } catch (error) {
    console.error('获取参评人员详情失败:', error)
  } finally {
    loading.value = false
  }
}

defineExpose({ open })
</script> 